package com.zhong.subject.domain.handler.subject;

import com.zhong.subject.common.enums.IsDeleteFlagEnum;
import com.zhong.subject.common.enums.SubjectInfoTypeEnum;
import com.zhong.subject.domain.bo.SubjectInfoBO;
import com.zhong.subject.domain.bo.SubjectOptionBO;
import com.zhong.subject.domain.convert.SubjectBriefConverter;
import com.zhong.subject.infra.basic.entity.SubjectBrief;
import com.zhong.subject.infra.basic.service.SubjectBriefService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * 简答题目的策略类
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler {

    @Resource
    private SubjectBriefService subjectBriefService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        //简答题目插入
        SubjectBrief subjectBrief = SubjectBriefConverter.INSTANCE.convertInfoBoToBrief(subjectInfoBO);
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        subjectBrief.setIsDelete(IsDeleteFlagEnum.UN_DELETE.getCode());
        subjectBriefService.insert(subjectBrief);
    }

    @Override
    public SubjectOptionBO query(Long subjectId) {
        //简答题目查询
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectId);

        SubjectBrief brief = subjectBriefService.queryByCondition(subjectBrief);

        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        subjectOptionBO.setSubjectAnswer(brief.getSubjectAnswer());

        return subjectOptionBO;
    }
}
